package com.bjc.chapter08;

/**
 * @program: jvm_demo
 * @description: 栈上分配测试
 * -Xmx1G -Xms1G -XX:-DoEscapeAnalysis -XX:+PrintGCDetails
 * @author: bjc
 * @create: 2022-01-20 22:06
 */
public class StackAllocation {

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            alloc();
        }
        //查看执行时间
        long end = System.currentTimeMillis();
        System.out.println("花费的时间为："+(end-start)+"ms");
        //为了方便查看堆内存中的对象个数：
        try {
            Thread.sleep(100000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static void alloc(){
        //未发生逃逸
        User user = new User();
    }

    static class User{}
}


